import { TestCases } from "./testCases";
import { url } from "@kit.ArkTS";

export const parse_url:TestCases = {
  "version": "1.4",
  "testCases": [
    {
      "documentation": "simple URL parsing",
      "params": {
        "Endpoint": "https://authority.com/custom-path"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://https-authority.com.example.com/path-is/custom-path")
        }
      }
    },
    {
      "documentation": "empty path no slash",
      "params": {
        "Endpoint": "https://authority.com"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://https-authority.com-nopath.example.com")
        }
      }
    },
    {
      "documentation": "empty path with slash",
      "params": {
        "Endpoint": "https://authority.com/"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://https-authority.com-nopath.example.com")
        }
      }
    },
    {
      "documentation": "authority with port",
      "params": {
        "Endpoint": "https://authority.com:8000/port"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://authority.com:8000/uri-with-port")
        }
      }
    },
    {
      "documentation": "http schemes",
      "params": {
        "Endpoint": "http://authority.com:8000/port"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("http://authority.com:8000/uri-with-port")
        }
      }
    },
    {
      "documentation": "arbitrary schemes are not supported",
      "params": {
        "Endpoint": "acbd://example.com"
      },
      "expect": {
        "error": "endpoint was invalid"
      }
    },
    {
      "documentation": "host labels are not validated",
      "params": {
        "Endpoint": "http://99_ab.com"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://http-99_ab.com-nopath.example.com")
        }
      }
    },
    {
      "documentation": "host labels are not validated",
      "params": {
        "Endpoint": "http://99_ab-.com"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://http-99_ab-.com-nopath.example.com")
        }
      }
    },
    {
      "documentation": "invalid URL",
      "params": {
        "Endpoint": "http://abc.com:a/foo"
      },
      "expect": {
        "error": "endpoint was invalid"
      },
      "skip": true
    },
    {
      "documentation": "IP Address",
      "params": {
        "Endpoint": "http://192.168.1.1/foo/"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("http://192.168.1.1/foo/is-ip-addr")
        }
      }
    },
    {
      "documentation": "IP Address with port",
      "params": {
        "Endpoint": "http://192.168.1.1:1234/foo/"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("http://192.168.1.1:1234/foo/is-ip-addr")
        }
      }
    },
    {
      "documentation": "IPv6 Address",
      "params": {
        "Endpoint": "https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443/is-ip-addr")
        }
      }
    },
    {
      "documentation": "weird DNS name",
      "params": {
        "Endpoint": "https://999.999.abc.blah"
      },
      "expect": {
        "endpoint": {
          "url": url.URL.parseURL("https://https-999.999.abc.blah-nopath.example.com")
        }
      }
    },
    {
      "documentation": "query in resolved endpoint is not supported",
      "params": {
        "Endpoint": "https://example.com/path?query1=foo"
      },
      "expect": {
        "error": "endpoint was invalid"
      }
    }
  ]
}
